package com.sjd.storehouse.mapper;


import com.sjd.storehouse.entity.AssistList;
import com.sjd.storehouse.entity.Center;
import com.sjd.storehouse.entity.Rent;
import com.sjd.storehouse.service.SqlService;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.UpdateProvider;

import java.util.List;

@Mapper
public interface StoreMapper {


    @Insert(value = "insert into center(id,name,spec,unit,num,create_time) " +
            "values (#{id},#{name},#{spec},#{unit},#{num},#{createTime})")
    int addCenter(Center center);

    @Select(value = "select * from center where (id like '%${param1}%' or name like '%${param1}%') and del_flag='0' " +
            "order by create_time desc limit ${param2},${param3}")
    List<Center> loadCenter(String query, int start, int limit);

    @UpdateProvider(method = "updateCenterByIdProvider", type = SqlService.class)
    int updateCenterById(Center center);

    @Select(value = "select count(1) from center where del_flag='0' and (id like '%${query}%' or name like '%${query}%')")
    int countCenter(String query);

    @Select(value = "select * from center where id = #{param1} and del_flag ='0'  ")
    Center getCenterById(String id);

    @Select(value = "select * from assist where id = #{param1} and del_flag !='1'  ")
    Center getAssistById(String id);

    @Insert(value = "insert into assist(id,name,spec,unit,num,kind,create_time,username,del_flag) " +
            "values (#{id},#{name},#{spec},#{unit},#{num},#{kind},#{createTime},#{username},#{delFlag})")
    int addAssist(Center assist);

    @Select(value = "select * from assist_list where del_flag ='0'  ")
    List<AssistList> loadAssistList();

    @Select(value = "select * from assist where kind = #{param1} and del_flag!='1' " +
            "order by create_time desc")
    List<Center> loadAssist(String kind);

    @Select(value = "select * from assist where del_flag = '2' order by create_time desc")
    List<Center> loadApp();

    @Select(value = "select * from assist_list where del_flag = '0' and id = #{param1}")
    AssistList getAssistListById(String kind);

    @UpdateProvider(method = "updateAssistByIdProvider", type = SqlService.class)
    int updateAssistById(Center assist);

    @Select(value = "select * from center where name = #{param1} and del_flag ='0'  ")
    Center getCenterByName(String name);

    @Insert(value = "insert into rent(id,assist_id,kind,username) " +
            "values (#{id},#{assistId},#{kind},#{username})")
    int addRent(Rent rent);

    @Select(value = "select * from rent where del_flag = '0' and assist_id = #{param1}")
    Rent getRentByAssistId(String assistId);

    @Select(value = "select * from rent where del_flag = '0' and kind = #{param1}")
    List<Rent> loadRent(String kind);

    @UpdateProvider(method = "updateRentByIdProvider", type = SqlService.class)
    int updateRentById(Rent rent);

    @Select(value = "select * from rent where del_flag = '0' and id = #{param1}")
    Rent getRentById(String id);
}
